package cn.udrm.water.base.v1.waterdelivery.repository;

import java.util.List;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.data.jpa.repository.EntityGraph;
import org.springframework.data.jpa.repository.EntityGraph.EntityGraphType;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import cn.udrm.water.base.v1.waterdelivery.entities.CanalSystem;

@Repository
public interface CanalSystemRepository extends JpaRepository<CanalSystem, String>
			, JpaSpecificationExecutor<CanalSystem>{
	
	@EntityGraph(value="CanalSystem.canalSystemExt", type=EntityGraphType.FETCH)
	public Page<CanalSystem> findAll(Specification<CanalSystem> specification, Pageable pageable);
	
	/********************获取渠道及其子渠道**********************/
	@Query(value="FROM CanalSystem")
	@EntityGraph(value="CanalSystem.childrens", type=EntityGraphType.FETCH)
	public List<CanalSystem> findAllChildrens();
	@Query(value="FROM CanalSystem c WHERE c.id=?1")
	@EntityGraph(value="CanalSystem.childrens", type=EntityGraphType.FETCH)
	public CanalSystem findChildrensById(String id);
	/*********************************************************/
	
	/********************获取渠道自身***************************/
	@Query(value="FROM CanalSystem")
	public List<CanalSystem> findAllSelf();
	@Query(value="FROM CanalSystem WHERE id=?1")
	public CanalSystem findSelfById(String id);
	/*********************************************************/

	/******************获取渠道所有关联**************************/
	@EntityGraph(value="CanalSystem.all", type=EntityGraphType.FETCH)
	public List<CanalSystem> findAll();
	@Query(value="FROM CanalSystem WHERE id=?1")
	@EntityGraph(value="CanalSystem.all", type=EntityGraphType.FETCH)
	public CanalSystem findSelfAllById(String id);
	/*********************************************************/
	
	/******************获取渠道及其断面*************************/
	@Query(value="FROM CanalSystem")
	@EntityGraph(value="CanalSystem.canalSystemSections", type=EntityGraphType.FETCH)
	public List<CanalSystem> findAllWithCanalSystemSections();
	@Query(value="FROM CanalSystem WHERE id=?1")
	@EntityGraph(value="CanalSystem.canalSystemSections", type=EntityGraphType.FETCH)
	public CanalSystem findWithCanalSystemSectionsById(String id);
	/*********************************************************/
	
	/******************获取渠道及其跌水**************************/
	@Query(value="FROM CanalSystem")
	@EntityGraph(value="CanalSystem.drops", type=EntityGraphType.FETCH)
	public List<CanalSystem> findAllWithDrops();
	@Query(value="FROM CanalSystem WHERE id=?1")
	@EntityGraph(value="CanalSystem.drops", type=EntityGraphType.FETCH)
	public CanalSystem findWithDropsById(String id);
	/*********************************************************/
	
	/********************获取渠道及其倒虹吸**********************/
	@Query(value="FROM CanalSystem")
	@EntityGraph(value="CanalSystem.invertedSiphons", type=EntityGraphType.FETCH)
	public List<CanalSystem> findAllWithInvertedSiphons();
	@Query(value="SELECT c FROM CanalSystem c WHERE c.id=?1")
	@EntityGraph(value="CanalSystem.invertedSiphons", type=EntityGraphType.FETCH)
	public CanalSystem findWithInvertedSiphonsById(String id);
	/*********************************************************/
	
	/******************获取渠道及其扬水站************************/
	@Query(value="FROM CanalSystem")
	@EntityGraph(value="CanalSystem.pumpingStations", type=EntityGraphType.FETCH)
	public List<CanalSystem> findAllWithPumpingStations();
	@Query(value="FROM CanalSystem WHERE id=?1")
	@EntityGraph(value="CanalSystem.pumpingStations", type=EntityGraphType.FETCH)
	public CanalSystem findWithPumpingStationsById(String id);
	/*********************************************************/
	
	/*****************获取渠道及其渡槽**************************/
	@Query(value="FROM CanalSystem")
	@EntityGraph(value="CanalSystem.sluices", type=EntityGraphType.FETCH)
	public List<CanalSystem> findAllWithSluices();
	@Query(value="FROM CanalSystem WHERE id=?1")
	@EntityGraph(value="CanalSystem.sluices", type=EntityGraphType.FETCH)
	public CanalSystem findWithSluicesById(String id);
	/*********************************************************/
	
	/******************获取渠道及其陡坡**************************/
	@Query(value="FROM CanalSystem")
	@EntityGraph(value="CanalSystem.steepSlopes", type=EntityGraphType.FETCH)
	public List<CanalSystem> findAllWithSteepSlopes();
	@Query(value="FROM CanalSystem WHERE id=?1")
	@EntityGraph(value="CanalSystem.steepSlopes", type=EntityGraphType.FETCH)
	public CanalSystem findWithSteepSlopesById(String id);
	/*********************************************************/
	
	/*******************获取渠道及其隧洞*************************/
	@Query(value="FROM CanalSystem")
	@EntityGraph(value="CanalSystem.tunnels", type=EntityGraphType.FETCH)
	public List<CanalSystem> findAllWithTunnels();
	@Query(value="FROM CanalSystem WHERE id=?1")
	@EntityGraph(value="CanalSystem.tunnels", type=EntityGraphType.FETCH)
	public CanalSystem findWithTunnelsById(String id);
	/*********************************************************/
	
	/*******************获取渠道及其闸门*************************/
	@Query(value="FROM CanalSystem")
	@EntityGraph(value="CanalSystem.waterGates", type=EntityGraphType.FETCH)
	public List<CanalSystem> findAllWithWaterGates();
	@Query(value="FROM CanalSystem WHERE id=?1")
	@EntityGraph(value="CanalSystem.waterGates", type=EntityGraphType.FETCH)
	public CanalSystem findWithWaterGatesById(String id);
	/*********************************************************/
	
}
